package com.budwk.app.sqfw.controllers.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.budwk.app.sqfw.enums.TemplateConfigEnum;
import com.budwk.app.sqfw.vo.SysTemplateConfigVO;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.openapi.annotation.ApiResponses;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ZY.Wang
 * @since 2023/10/19
 */
@IocBean
@At("/platform/sqfw/formSummaryConfig")
@ApiDefinition(tag = "系统模板配置")
@Slf4j
public class SqfwFormSummaryConfigController {

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "根据条件查询场所名称")
    @ApiResponses
    @SLog(tag = "获取系统文件模板")
    @SaCheckLogin
    public Result<?> getTemplateList() {

        Map<String, List<SysTemplateConfigVO>> resultMap = Maps.newTreeMap();
        TemplateConfigEnum[] templateConfigEnums = TemplateConfigEnum.values();
        for (TemplateConfigEnum templateConfigEnum : templateConfigEnums) {
            String serviceOrderType = templateConfigEnum.getServiceOrderType();

            SysTemplateConfigVO vo = new SysTemplateConfigVO();
            vo.setCode(templateConfigEnum.getTemplateCode());
            vo.setName(templateConfigEnum.getTemplateName());
            vo.setServiceOrderTypeName(serviceOrderType);

            if (resultMap.containsKey(serviceOrderType)) {
                resultMap.get(serviceOrderType).add(vo);
            } else {
                resultMap.put(serviceOrderType, Lists.newArrayList(vo));
            }
        }

        return Result.success(resultMap);
    }

}
